package leetcode.editor.cn;

public class _55_JumpGame {
    public static void main(String[] args) {
        Solution solution = new _55_JumpGame().new Solution();
        int[] nums = new int[]{3, 2, 1, 0, 4};
        boolean b = solution.canJump(nums);
        System.out.println(b);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean canJump(int[] nums) {
            int n = nums.length;
            int farest = 0;
            for (int i = 0; i < n; i++) {
                farest = Math.max(farest, i + nums[i]);

                // 如果遇到了 0 还是最远, 不能继续往下循环了
                if (farest == i) {
                    break;
                }
            }
            return farest >= n - 1;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}